<template>
    <div class="follower-container">
        <ul class="agree-container">
            <li v-for="item in data" :key="item.id" class="agree-item">
                <a class="user-avatar">
                    <img class="avatar-item" :src="item.user.avatar" :alt="item.user.name" />
                </a>
                <div class="main">
                    <div class="info">
                        <div class="user-info">
                            <a class="username">{{ item.user.name }}</a>
                        </div>
                        <div class="interaction-hint">
                            <span>开始关注您了&nbsp;</span>
                            <span>{{ item.followTime }}</span>
                        </div>
                    </div>
                    <div class="extra">
                        <button class="reds-button-new follow-button large" :class="{ primary: !item.mutual }"
                            @click="handleFollow(item)">
                            <span class="reds-button-new-box">
                                <span class="reds-button-new-text">
                                    {{ item.mutual ? '已关注' : '回关' }}
                                </span>
                            </span>
                        </button>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</template>

<script setup lang="ts">
defineProps<{
    data: Array<{
        id: number
        user: {
            name: string
            avatar: string
        }
        followTime: string
        mutual: boolean
    }>
}>()

const emit = defineEmits(['follow'])

const handleFollow = (item: any) => {
    if (!item.mutual) {
        emit('follow', item.id)
    }
}
</script>

<style lang="less" scoped>
.follower-container {
    padding: 16px 0;

    .agree-container {
        width: 100%;
        margin: 0;
        padding: 0;
        list-style: none;

        .agree-item {
            display: flex;
            padding: 16px 0;
            border-bottom: 1px solid rgba(0, 0, 0, 0.08);

            &:last-child {
                border-bottom: none;
            }

            .user-avatar {
                margin-right: 24px;
                flex-shrink: 0;

                .avatar-item {
                    width: 48px;
                    height: 48px;
                    border-radius: 50%;
                    object-fit: cover;
                    border: 1px solid rgba(0, 0, 0, 0.08);
                }
            }

            .main {
                flex: 1;
                display: flex;
                justify-content: space-between;
                align-items: center;

                .info {
                    .username {
                        font-size: 16px;
                        font-weight: 600;
                        color: #333;
                        text-decoration: none;
                    }

                    .interaction-hint {
                        font-size: 14px;
                        color: rgba(51, 51, 51, 0.6);
                        margin-top: 4px;
                    }
                }

                .extra {
                    .reds-button-new {
                        &.primary {
                            background-color: #ff2e4d;
                            color: white;
                        }

                        &:not(.primary) {
                            background-color: #f5f5f5;
                            color: rgba(51, 51, 51, 0.8);
                        }

                        &.large {
                            height: 36px;
                            padding: 0 24px;
                            font-size: 14px;
                            border-radius: 18px;
                        }
                    }
                }
            }
        }
    }
}
</style>